﻿using System;

class SquareRootOfInteger
{
    static void Main()
    {
        //Exercise 1.
        //Write a program that reads an integer number and calculates and prints its square root. If the number is invalid or 
        //negative, print "Invalid number". In all cases finally print "Good bye". Use try-catch-finally.

        try
        {
            Console.Write("Enter a positive integer: ");
            int number = int.Parse(Console.ReadLine());
            if (number < 0)
            {
                throw new FormatException();
            }
            double result = Math.Sqrt(number);
            Console.WriteLine("The square root is:  {0}", result);           
        }        
        
        catch (FormatException fe)
        {
            Console.WriteLine("Invalid number: {0}", fe.Message);

        }
        catch (OverflowException)
        {
            Console.WriteLine("The number is too big or too small!");
        }

        finally
        {
            Console.WriteLine("Good bye!");
        }

    }
}

